Text strings are used for file names and plot labels. Strings are enclosed in double quotes and can contain blanks or punctuation but they cannot contain a RETURN.
Variables can be defined or assigned as strings. If the variable is to be evaluated many times it is better to assign the string so that multiple copies of the string do not need to be created.
--- sprintf
Numeric results can be converted to strings with the built-in function sprintf(format,n). This function is essentially the same as the C standard library function.
The format parameter is a string which controls the conversion. The format must contain a single conversion specification. Any characters that are not part of the conversion specification are copied directly to the result string. A conversion specification begins with a % character. A % character can be ouput by using %%.
The conversion has the following form: (brackets indicate optional values).
╩%[flags][size][.precision]conversion
flag
- left justify
+ include leading plus
space include a leading space
0 pad with leading zeros
# use alternate form
size
minimum number of output characters
The field is padded with spaces if needed.
precision
floating point number of digits after the decimal point
integer minimum number of digits
string maximum number of characters
conversion
character n output # alternate form
c ascii code single character
d integer signed integer
e E floating point E format always include point
f floating point fixed point format always include point
g G floating point smaller of f or e include trailing zeros
i integer signed integer
o integer octal force leading zero
s string string not allowed
u integer unsigned integer
x X integer hexadecimal use 0x prefix
examples:
format sprintf(format,42)
"n=%f" "n=42.000000"
"n=%e" "n=4.200000e+01"
"n=%E" "n=4.200000E+01"
"n=%g" "n=42"
"n=%.2f" "n=42.00"
"n=%10.2f" "n= 42.00"
"n=%-10.2f" "n=42.00 "
"n=%d" "n=42"
"n=%X" "n=2A"
"n=%o" "n=52"
"n=%c" "n=*"
--- Concatenation
The sprintf function only allows one conversion in the format string but results can be joined together with the concatenation operator '|' . Both operands must be strings.
"what" | "not":"whatnot"
--- String Output
String results are shown in quotes. The table command can be used to output arrays with string elements.
weekdays = {"mon","tues","wed","thurs","fri"}
table {weekdays}
╩╩╩╩"mon"╩╩╩╩"tues"╩╩╩╩"wed" ╩╩╩╩"thurs"╩╩╩╩"fri"
The write() function will write out strings for the special case of a 2D array of strings and a TEXT file. Each string is written out with no quotes or separators. A line in the output file corresponds to a row in the 2D array.
An explicit index on a string will extract the ASCII value of a single character
"tues"[1]:116 -- 116 is the ASCII code for 't'
"tues"[2]:117 -- 117 is the ASCII code for 'u'
Strings are not general purpose objects. They are handled in the above special cases. Most other operations will have no effect on the string and will not generate any error messages. In cases where a string is not allowed, an undefined or an array of ASCII values is used.